package com.example.treasure_back.service;

import com.example.treasure_back.enumerate.ExchangeType;
import com.example.treasure_back.mapper.OrderMapper;
import com.example.treasure_back.model.OrderModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private ExchangeRecordService exchangeRecordService;

    public void insertOrder(String email, String province, String city, String addr, String name, String phone,Integer id){
        OrderModel orderModel = new OrderModel();
        orderModel.setEmail(email);
        orderModel.setProvince(province);
        orderModel.setCity(city);
        orderModel.setAddr(addr);
        orderModel.setName(name);
        orderModel.setPhone(phone);
        Integer goodsId = exchangeRecordService.getGoodsIdById(id);
        exchangeRecordService.changeStatus(id, ExchangeType.ALREADY_EXCHANGE);
        orderModel.setGoodsName(goodsService.getGoodsNameById(goodsId));
        orderModel.setGoodsImage(goodsService.getGoodsImageById(goodsId));
        orderModel.setStatus(0);
        orderMapper.insert(orderModel);
    }
}
